package cn.edu.wdu.gaojie.reflection.homework1;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author gaojie  gao4433@qq.com
 * @Description
 * @date 2021/11/29 15:51
 * @since 1.8
 */
public class AppCore {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException, NoSuchFieldException {
        // TODO
        // 1. 通过反射得到 CustomerService 类的实例 c
        // 2. 调用实例 c 的 say 方法并正确输出结果
        Class<?> C = Class.forName("cn.edu.wdu.gaojie.reflection.homework1.CustomerService");
        Object c = C.newInstance();

        //方法二
        Field service = C.getDeclaredField("service");
        service.setAccessible(true);
        Class<?> U = Class.forName("cn.edu.wdu.gaojie.reflection.homework1.UserService");
        service.set(c, U.newInstance());

        Method say = C.getDeclaredMethod("say");
        say.invoke(c);

    }
}

